/**
 * Created by mantoo on 2018/3/16.
 */
var myChart = echarts.init(document.getElementById('RainRuleChart'));
myChart.setOption({
        title: {
            text: '爬取结点耗时与数据量数据图',
            subtext: '数据获取自/Job51_shezhao/spider_main.pu脚本',
            x: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                animation: false
            }
        },
        legend: {
            data: ['所需时间', '每条数据数据量'],
            x: 'left'
        },
        toolbox: {
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                restore: {},
                saveAsImage: {}
            }
        },
        axisPointer: {
            link: {xAxisIndex: 'all'}
        },
        dataZoom: [
            {
                show: true,
                realtime: true,
                start: 80,
                end: 100,
                xAxisIndex: [0, 1]
            },
            {
                type: 'inside',
                realtime: true,
                start: 80,
                end: 100,
                xAxisIndex: [0, 1]
            }
        ],
        grid: [{
            left: 50,
            right: 50,
            height: '35%'
        }, {
            left: 50,
            right: 50,
            top: '55%',
            height: '35%'
        }],
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                axisLine: {onZero: true},
                data: []
            },
            {
                gridIndex: 1,
                type: 'category',
                boundaryGap: false,
                axisLine: {onZero: true},
                data: [], //时间段
                position: 'bottom'
            }
        ],
        yAxis: [
            {
                name: '所需时间(ms)',
                type: 'value',
                // max: 0 //最大值
                min:0
            },
            {
                gridIndex: 1,
                //inverse: true,
                name: '每条数据数据量(条/字符)',
                type: 'value'
            }
        ],
        series: [
            {
                name: '每条数据爬取所耗时间',
                type: 'line',
                symbolSize: 8,
                hoverAnimation: false,
                areaStyle: {normal: {}},
                data: []
            },
            {
                name: '每条数据数据量',
                type: 'line',
                xAxisIndex: 1,
                yAxisIndex: 1,
                symbolSize: 8,
                hoverAnimation: false,
                areaStyle: {normal: {}},
                data: [] //数据
            }
        ]
 });
myChart.showLoading();
$("#start_data_51job").click(function() {

    // alert("启动了");
    var timeData = [];

    timeData = timeData.map(function (str) {
        return str.replace('2009/', '');
    });


    setInterval(function () {
        $.get('/zfq/admin/gainRule/reRule-data/?key=51job&operate=chart').done(function (data) {
            console.log(data);
            var data =  JSON.parse(data);
            console.log(data);
            // data1.push(data.data1);
            // data2.push(data.data2);
            // dataTime.push(data.dataTime);
            console.log(data['chart_date']);
            console.log(data['chart_data']);
            myChart.hideLoading();
            // 填入数据
            myChart.setOption({
                xAxis: [{
                    data: data['chart_date']
                }, {
                    data: data['chart_date']
                }],
                 yAxis: [{
                     min:data['yAxisMin']
                }],
                // yAxis:[{
                //     max:data.max1
                // },{
                //     max:data.max2
                // }],
                series: [{
                    // 根据名字对应到相应的系列
                    data: data['chart_data']
                },{
                    // 根据名字对应到相应的系列
                    data: data['self_thisStrList']
                }]
            });
        });

console.log(option);
}, 1000);
});

